<?php
    use User\Model\DailySignModel;
?>
<link href="/Public/css/common/switchery.css" rel="stylesheet"/>
<style>
    .nav-tabs li.active{border-bottom:3px solid blue}
    .panel-body{min-height:800px;}
    .step1-tab li{width:10%;height:40px;float:left;padding:10px 10px;text-align:center;cursor:pointer;}
    .step1-tab li.active {background-color:#3896DC;}
    .step1-tab li a{padding:10px 22px;text-decoration:none}
    .step1-tab li.active a{color:#fff}

    .preview-tab li{width:33%;height:40px;float:left;padding:10px 10px;text-align:center;cursor:pointer}
    .preview-tab li.active{background-color:#3896DC;color:#fff}
    .preview{position:absolute;top:100px;right:100px;z-index:1}
    .preview-frame1{width:320px;height:520px;border:1px solid #ccc;text-align:center;z-index:1;
        background-image:url("/Public/images/daily_sign/calendar1.png");background-size:cover;background-repeat:no-repeat}
    .preview-frame2{width:320px;height:520px;border:1px solid #ccc;text-align:center;z-index:1;
        background-image:url("/Public/images/daily_sign/calendar2.png");background-size:cover;background-repeat:no-repeat}

    .marginLeft100{margin-left:100px}
    .marginLeft30{margin-left:30px}
    .marginRight10{margin-right:10px}
    .marginTop10{margin-top:10px}
    .btn-black{background-color:black}
    .step1{width:100px;margin:20px 0 0 100px}

    .btn{padding:5px}
    .add-rule{margin-left:204px;}
    .add-rule button{width:350px;margin-top:10px}

    .table>thead>tr>th{text-align: center}
    .table>tbody>tr>td{vertical-align: middle;text-align: center}
    .table>tbody>tr>td>a{margin-top:5px}
    .btn-custom{color:white} .btn-custom:hover{color:white}
    .color1{background-color:#199ED8} .color2{background-color:#999933} .color3{background-color:#5CB85C}
    .color4{background-color:#F0AD4E} .color5{background-color:#D9534F} .color6{background-color:#FFCC33}
    .color7{background-color:#FF66CC} .color8{background-color:#66CCFF} .color9{background-color:#660000}

     .btn-black:hover{color:white;background-color:black}
    .panel-body{padding:0}
    .customImage{width:100px;height:100px}

</style>
<div class="row">
    <div class="col-lg-12">
        <div class="form-horizontal">
            <input type="hidden" name="id" value="{$id}">
            <section class="panel sec-step1" <if condition="$step neq 1">style="display:none"</if>>
                <header class="panel-heading">
                    <if condition="$id eq -1">新建<else/>{$daily_sign["title"]} - 编辑</if>
                </header>
                <header class="panel-heading" style="border-bottom:0">
                    <button class="btn btn-info marginLeft100 marginRight10 btn-black" type="button">基础设置</button>
                    <img src="/Public/images/daily_sign/arrowRight.png">
                    <!--<button class="btn btn-default marginRight10" type="button" disabled="disabled">积分规则设置</button>-->
                    <!--<img src="/Public/images/daily_sign/arrowRight.png">-->
                    <button class="btn btn-default" type="button" disabled="disabled">个性设置</button>
                </header>
                <div class="panel-body">
                    <div class="form-horizontal tab-content">
                        <div class="preview">
                            <if condition="($daily_sign.type eq DailySignModel::CALENDAR_TYPE_1) OR ($daily_sign.type eq null)">
                                <div class="frame preview-frame1"></div>
                            <else/>
                                <div class="frame preview-frame2"></div>
                            </if>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span> 活动标题</label>
                            <div class="col-lg-4">
                                <input type="text" class="form-control" title="活动标题" name="title" value="{$daily_sign['title']}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span> 日历类型</label>
                            <div class="col-lg-4">
                                <label class="radio-inline">
                                    <input type="radio" name="type" <if condition="($daily_sign.type eq DailySignModel::CALENDAR_TYPE_1) OR ($daily_sign.type eq null)">checked="checked"</if> value="<?php echo DailySignModel::CALENDAR_TYPE_1; ?>"
                                        onclick="$('.frame').removeClass('preview-frame2').addClass('preview-frame1');$('.attach-image').hide()">&nbsp;极简版
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="type" <if condition="$daily_sign.type eq DailySignModel::CALENDAR_TYPE_2">checked="checked"</if> value="<?php echo DailySignModel::CALENDAR_TYPE_2; ?>"
                                        onclick="$('.frame').removeClass('preview-frame1').addClass('preview-frame2');$('.attach-image').show()">&nbsp;图文版
                                </label>
                            </div>
                        </div>

                        <div class="attach-image" <if condition="($daily_sign.type eq DailySignModel::CALENDAR_TYPE_1) OR ($daily_sign.type eq null)">style="display:none"</if>>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span> 图库</label>
                                <div class="col-lg-4">
                                    <if condition="$images eq null">
                                        <div class="col-lg-4"><a href="/User/DailySign/attach?type=2" class="btn btn-default">点击设置</a></div>
                                    <else/>
                                        <select name="attach_image" class="form-control">
                                            <option value="-1">--请选择--</option>
                                            <volist name="images" id="img">
                                                <option value="{$img.id}" <if condition="$img.id eq $daily_sign['attach_image']">selected</if>>{$img['title']}</option>
                                            </volist>
                                        </select>
                                    </if>
                                </div>
                            </div>

                            <if condition="$images neq null">
                                <div class="form-group" style="margin-left:100px">
                                    <label class="col-sm-2 col-sm-2 control-label">排列方式</label>
                                    <div class="col-lg-4">
                                        <label class="radio-inline">
                                            <input type="radio" name="image_sort" <if condition="($daily_sign.image_sort eq DailySignModel::SORT_1) OR ($daily_sign.image_sort eq null)">checked="checked"</if> value="<?php echo DailySignModel::SORT_1; ?>">&nbsp;正常排序
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="image_sort" <if condition="$daily_sign.image_sort eq DailySignModel::SORT_2">checked="checked"</if> value="<?php echo DailySignModel::SORT_2; ?>">&nbsp;随机排序
                                        </label>
                                    </div>
                                </div>
                            </if>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span> 语录库</label>
                            <div class="col-lg-4">
                                <if condition="$words eq null">
                                    <div class="col-lg-4"><a href="/User/DailySign/attach" class="btn btn-default">点击设置</a></div>
                                <else/>
                                    <select name="attach_word" class="form-control">
                                        <option value="-1">--请选择--</option>
                                        <volist name="words" id="wd">
                                            <option value="{$wd.id}" <if condition="$wd.id eq $daily_sign['attach_word']">selected</if>>{$wd['title']}</option>
                                        </volist>
                                    </select>
                                </if>
                            </div>
                        </div>

                        <if condition="$words neq null">
                            <div class="form-group" style="margin-left:100px">
                                <label class="col-sm-2 col-sm-2 control-label">排列方式</label>
                                <div class="col-lg-4">
                                    <label class="radio-inline">
                                        <input type="radio" name="word_sort" <if condition="($daily_sign.word_sort eq DailySignModel::SORT_1) OR ($daily_sign.word_sort eq null)">checked="checked"</if> value="<?php echo DailySignModel::SORT_1; ?>">&nbsp;正常排序
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="word_sort" <if condition="$daily_sign.word_sort eq DailySignModel::SORT_2">checked="checked"</if> value="<?php echo DailySignModel::SORT_2; ?>">&nbsp;随机排序
                                    </label>
                                </div>
                            </div>
                        </if>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color:red">*</span> 宜忌文库</label>
                            <div class="col-lg-4">
                                <if condition="$advices eq null">
                                    <div class="col-lg-4"><a href="/User/DailySign/attach?type=3" class="btn btn-default">点击设置</a></div>
                                <else/>
                                    <select name="attach_advice" class="form-control">
                                        <option value="-1">--请选择--</option>
                                        <volist name="advices" id="ad">
                                            <option value="{$ad.id}" <if condition="$ad.id eq $daily_sign['attach_advice']">selected</if>>{$ad['title']}</option>
                                        </volist>
                                    </select>
                                </if>
                            </div>
                        </div>

                        <if condition="$advices neq null">
                            <div class="form-group" style="margin-left:100px">
                                <label class="col-sm-2 col-sm-2 control-label">排列方式</label>
                                <div class="col-lg-4">
                                    <label class="radio-inline">
                                        <input type="radio" name="advice_sort" <if condition="($daily_sign.advice_sort eq DailySignModel::SORT_1) OR ($daily_sign.advice_sort eq null)">checked="checked"</if> value="<?php echo DailySignModel::SORT_1; ?>">&nbsp;正常排序
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="advice_sort" <if condition="$daily_sign.advice_sort eq DailySignModel::SORT_2">checked="checked"</if> value="<?php echo DailySignModel::SORT_2; ?>">&nbsp;随机排序
                                    </label>
                                </div>
                            </div>
                        </if>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">添加元素</label>
                            <div class="col-lg-4">
                                <label class="checkbox-inline">
                                    <input type="checkbox" name="has_weather" <if condition="$daily_sign.has_weather eq DailySignModel::HAS_WEATHER_YES">checked="checked"</if> value="<?php echo DailySignModel::HAS_WEATHER_YES; ?>">&nbsp;天气
                                </label>
                                <label class="checkbox-inline">
                                    <input type="checkbox" name="has_festival" <if condition="$daily_sign.has_festival eq DailySignModel::HAS_FESTIVAL_YES">checked="checked"</if> value="<?php echo DailySignModel::HAS_FESTIVAL_YES; ?>">&nbsp;节日
                                </label>
                            </div>
                        </div>
                        <button type="button" class="btn btn-info step1" id="step1" onclick="step1()">提交</button>
                    </div>
                </div>
            </section>

            <section class="panel sec-step2" style="display:none">
                <header class="panel-heading">
                    <if condition="$id eq -1">奖项设置<else/>{$daily_sign["title"]} - 奖项设置</if>
                </header>
                <header class="panel-heading" style="border-bottom:0">
                    <button class="btn btn-default marginLeft100 marginRight10" type="button" disabled="disabled">基础设置</button>
                    <img src="/Public/images/daily_sign/arrowRight.png">
                    <button class="btn btn-info marginRight10 btn-black" type="button">积分规则设置</button>
                    <img src="/Public/images/daily_sign/arrowRight.png">
                    <button class="btn btn-default" type="button" disabled="disabled">个性设置</button>
                </header>
                <div class="panel-body">
                    <div class="form-horizontal tab-content">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">每日签到可得</label>
                            <div class="col-lg-4">
                                <div class="input-group">
                                    <input type="text" class="form-control" title="每日签到可得" name="daily_credit" value="{$daily_sign['daily_credit']}">
                                    <span class="input-group-addon">分</span>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">连续签到积分规则</label>
                            <volist name="continue_rules" id="cr">
                                <if condition="1"><label class="col-sm-2 col-sm-2 control-label"></label></if>
                                <div class="col-lg-4">
                                    <input type="hidden" class="continue-value" value="">
                                    <input type="text" class="form-control" disabled="disabled" value="">
                                </div>
                                <button type="button" class="btn btn-primary">编辑</button>
                                <button type="button" class="btn btn-primary">删除</button><br>
                            </volist>
                            <div class="append-continue"></div>
                            <div class="add-rule"><button type="button" onclick="addContinueRule()" class="btn btn-default">+</button></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">累计签到规则</label>
                            <volist name="total_rules" id="cr">
                                <if condition="1"><label class="col-sm-2 col-sm-2 control-label"></label></if>
                                <div class="col-lg-4">
                                    <input type="hidden" class="total-value" value="">
                                    <input type="text" class="form-control" disabled="disabled" value="">
                                </div>
                                <button type="button" class="btn btn-primary">编辑</button>
                                <button type="button" class="btn btn-primary">删除</button><br>
                            </volist>
                            <div class="append-total"></div>
                            <div class="add-rule"><button type="button" onclick="addTotalRule()" class="btn btn-default">+</button></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">分享朋友圈可得</label>
                            <div class="col-lg-4">
                                <div class="input-group">
                                    <input type="text" class="form-control" title="分享朋友圈可得" name="share_credit" value="{$daily_sign['share_credit']}">
                                    <span class="input-group-addon">分</span>
                                </div>
                            </div>
                        </div>
                        <button type="button" class="btn btn-info step2" id="step2" onclick="step2()">提交</button>
                    </div>
                </div>
            </section>

            <section class="panel sec-step3" <if condition="$step neq 3">style="display:none"</if>>
                <header class="panel-heading">
                    <if condition="$id eq -1">新建<else/>{$daily_sign["title"]} - 编辑</if>
                </header>
                <header class="panel-heading" style="border-bottom:0">
                    <button class="btn btn-default marginRight10" disabled="disabled" type="button">基础设置</button>
                    <img src="/Public/images/daily_sign/arrowRight.png">
                    <!--<button class="btn btn-default marginRight10" type="button" disabled="disabled">积分规则设置</button>-->
                    <!--<img src="/Public/images/daily_sign/arrowRight.png">-->
                    <button class="btn btn-info btn-black" type="button">个性设置</button>
                    <div class="marginTop10">
                        <button style="margin-left:7px" class="btn btn-custom color3" onclick="addCustom()">新增</button>
                    </div>
                </header>
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>日期</th>
                                    <th>语录文案</th>
                                    <th>作者</th>
                                    <th>宜忌类型</th>
                                    <th>宜忌文案</th>
                                    <if condition="$daily_sign.type eq DailySignModel::CALENDAR_TYPE_2"><th>图库</th></if>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <volist name="list" id="item">
                                    <tr>
                                        <td>{$item.id}</td>
                                        <td class="custom-date-{$item.id}">{$item.date}</td>
                                        <td class="custom-word-{$item.id}">{$item.word}</td>
                                        <td class="custom-author-{$item.id}">{$item.author}</td>
                                        <td class="custom-type-{$item.id}" data-type="{$item.advice_type}">
                                            <if condition="$item.advice_type eq DailySignModel::ATTACHMENT_TYPE_GOOD">宜<else/>忌</if>
                                        </td>
                                        <td class="custom-advice-{$item.id}">{$item.advice}</td>
                                        <if condition="$daily_sign.type eq DailySignModel::CALENDAR_TYPE_2">
                                            <td><if condition="$item.image neq null"><img class="customImage customImage-{$item.id}" src="{$item.image}"></if></td>
                                        </if>
                                        <td>{$item.createdate}</td>
                                        <td>
                                            <button type="button" onclick="editCustomItem({$item['id']})" class="btn btn-custom color1">编辑</button>
                                            <button type="button" onclick="statusCustom({$item['id']})" class="btn btn-custom color5">删除</button>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                        <div class="pages">
                            {$page}
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="continue_rule" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">连续签到积分规则</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon">连续</span>
                    <input type="text" class="form-control" name="continue_day" value="" placeholder="数字">
                    <span class="input-group-addon">天，额外赠送</span>
                    <input type="text" class="form-control" name="continue_credit" value="" placeholder="数字">
                    <span class="input-group-addon">分</span>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="addContinueItem()">确定</button>
            </div>
        </div>
    </div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="total_rule" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">累计签到规则</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon">累计</span>
                    <input type="text" class="form-control" name="total_day" value="" placeholder="数字">
                    <span class="input-group-addon">天，额外赠送</span>
                    <input type="text" class="form-control" name="total_credit" value="" placeholder="数字">
                    <span class="input-group-addon">分</span>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="addTotalItem()">确定</button>
            </div>
        </div>
    </div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="custom" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">个性设置</h4>
            </div>
            <div class="modal-body form-horizontal">
                <input type="hidden" name="custom_id" value="-1">

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">选择日期</label>
                    <div class="col-lg-6">
                        <input type="text" name="custom_date" class="form-control" id="date-picker1" readonly>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">语录文案</label>
                    <div class="col-lg-6">
                        <input type="text" class="form-control" name="custom_word" value="">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">语录作者</label>
                    <div class="col-lg-6">
                        <input type="text" class="form-control" name="custom_author" value="">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">宜忌类型</label>
                    <div class="col-lg-4">
                        <label class="radio-inline">
                            <input type="radio" name="advice_type" checked="checked" value="<?php echo DailySignModel::ATTACHMENT_TYPE_GOOD; ?>"> 宜
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="advice_type" value="<?php echo DailySignModel::ATTACHMENT_TYPE_BAD; ?>">&nbsp;忌
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">宜忌文案</label>
                    <div class="col-lg-6">
                        <input type="text" class="form-control" name="custom_advice" value="">
                    </div>
                </div>

                <if condition="$daily_sign.type eq DailySignModel::CALENDAR_TYPE_2">
                    <div class="form-group">
                        <label class="col-lg-2 col-sm-2 control-label">图库</label>
                        <div class="col-lg-6">
                            <img class="custom-img" src="" width="100px" height="100px">
                            <input type="file" id="custom_image" accept="image/gif,image/jpeg,image/jpg,image/png">
                            <input type="hidden" name="custom_image" value="">
                        </div>
                    </div>
                </if>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="updateCustom()">确定</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/Public/js/laydatenew/laydate.js"></script>
<script type="text/javascript">
    laydate.render({
        elem: '#date-picker1'
    });

    function addContinueRule(){
        $('#continue_rule').modal('show');
        $('input[name=continue_day]').val('');
        $('input[name=continue_credit]').val('');
    }

    function addTotalRule(){
        $('#total_rule').modal('show');
        $('input[name=total_day]').val('');
        $('input[name=total_credit]').val('');
    }

    function addCustom(){
        $('#custom').modal('show');
        $('input[name=custom_date]').val('');
        $('input[name=custom_word]').val('');
        $('input[name=custom_author]').val('');
        $('input[name=advice_type]:eq(0)').prop('checked', 'checked');
        $('input[name=custom_advice]').val('');
        $('.custom-img').attr('src', '');
        $('input[name=custom_image]').val('');
    }

    function addContinueItem(){
        var continue_day = $('input[name=continue_day]').val();
        var continue_credit = $('input[name=continue_credit]').val();
        if(continue_day <= 0 || continue_day === ''){
            alert('连续天数不能为空');
            return false;
        }
        if(continue_credit <= 0 || continue_credit === ''){
            alert('赠送积分不能为空');
            return false;
        }
        var html = '';
        var str = '连续'+continue_day+'天，额外赠送'+continue_credit+'分';
        var continue_value = continue_day+','+continue_credit;
        var num = $('.continue-value').length;
        if(num > 0){
            html += '<label class="col-sm-2 col-sm-2 control-label marginTop10"></label>';
        }
        html += '<div class="col-lg-4">';
        html += '   <input type="hidden" class="continue-value" value="'+continue_value+'">';
        html += '   <input type="text" class="form-control" disabled="disabled" value="'+str+'">';
        html += '</div>';
        html += '<button type="button" class="btn btn-primary">编辑</button> ';
        html += '<button type="button" class="btn btn-primary">删除</button><br>';
        $('.append-continue').append(html);
        $('#continue_rule').modal('hide');
    }

    function addTotalItem(){
        var total_day = $('input[name=total_day]').val();
        var total_credit = $('input[name=total_credit]').val();
        if(total_day <= 0 || total_day === ''){
            alert('累计天数不能为空');
            return false;
        }
        if(total_credit <= 0 || total_credit === ''){
            alert('赠送积分不能为空');
            return false;
        }
        var html = '';
        var str = '累计'+total_day+'天，额外赠送'+total_credit+'分';
        var total_value = total_day+','+total_credit;
        var num = $('.total-value').length;
        if(num > 0){
            html += '<label class="col-sm-2 col-sm-2 control-label marginTop10"></label>';
        }
        html += '<div class="col-lg-4">';
        html += '   <input type="hidden" class="total-value" value="'+total_value+'">';
        html += '   <input type="text" class="form-control" disabled="disabled" value="'+str+'">';
        html += '</div>';
        html += '<button type="button" class="btn btn-primary">编辑</button> ';
        html += '<button type="button" class="btn btn-primary">删除</button><br>';
        $('.append-total').append(html);
        $('#total_rule').modal('hide');
    }

    function updateCustom(){
        var id = $('input[name=id]').val();
        var custom_id = $('input[name=custom_id]').val();
        var custom_date = $('input[name=custom_date]').val();
        var custom_word = $('input[name=custom_word]').val();
        var custom_author = $('input[name=custom_author]').val();
        var advice_type = $('input[name=advice_type]:checked').val();
        var custom_advice = $('input[name=custom_advice]').val();
        var custom_image = $('input[name=custom_image]').val();
        $.ajax({
            url: "/User/DailySign/updateCustom",
            type: "post",
            dataType: 'json',
            data: {id: id,custom_id: custom_id,custom_date: custom_date,custom_word: custom_word,
                custom_author: custom_author,advice_type: advice_type,custom_advice: custom_advice,
                custom_image: custom_image},
            success:function(result){
                if(result['code'] === 0){
                    alert('提交成功');
                    window.location.reload();
                }else{
                    alert('提交失败');
                }
            }
        });
    }

    function editCustomItem(id){
        var custom_date = $('.custom-date-'+id).text();
        var custom_word = $('.custom-word-'+id).text();
        var custom_author = $('.custom-author-'+id).text();
        var custom_advice = $('.custom-advice-'+id).text();
        var advice_type = $('.custom-type-'+id).data('type');
        var custom_image = $('.customImage-'+id).attr('src');
        $('#custom').modal('show');
        $('input[name=custom_id]').val(id);
        $('input[name=custom_date]').val(custom_date);
        $('input[name=custom_word]').val(custom_word);
        $('input[name=custom_author]').val(custom_author);
        var i = advice_type - 1;
        $('input[name=advice_type]:eq('+i+')').prop('checked', 'checked');
        $('input[name=custom_advice]').val(custom_advice);
        $('.custom-img').attr('src', custom_image);
        $('input[name=custom_image]').val(custom_image);
    }

    function statusCustom(id){
        if(!confirm('确认删除吗？')) return false;
        $.ajax({
            data: {id: id},
            dataType: 'json',
            url: '/User/DailySign/statusCustom',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
    }

    function step1(){
        var id = $('input[name=id]').val();
        if($('.step1').hasClass('next-step')){
            // $('.sec-step1').hide();
            // $('.sec-step2').show();
            window.location.href = '/User/DailySign/edit?id='+id+'&step=3';
        }else{
            var title = $('input[name=title]').val();
            var type = $('input[name=type]:checked').val();
            var attach_image = $('select[name=attach_image] option:selected').val();
            var attach_word = $('select[name=attach_word] option:selected').val();
            var attach_advice = $('select[name=attach_advice] option:selected').val();
            var image_sort = $('input[name=image_sort]:checked').val();
            var word_sort = $('input[name=word_sort]:checked').val();
            var advice_sort = $('input[name=advice_sort]:checked').val();
            var has_weather = 0;
            var has_festival = 0;
            if($('input[name=has_weather]').prop('checked') === true){
                has_weather = 1;
            }
            if($('input[name=has_festival]').prop('checked') === true){
                has_festival = 1;
            }
            if(title === ''){
                alert('活动标题不能为空');
                return false;
            }
            if((!attach_image || attach_image === '-1') && type === '<?php echo DailySignModel::CALENDAR_TYPE_2; ?>'){
                alert('图库不能为空');
                return false;
            }
            if(!attach_word || attach_word === '-1'){
                alert('语录库不能为空');
                return false;
            }
            if(!attach_advice || attach_advice === '-1'){
                alert('宜忌文库不能为空');
                return false;
            }
            $.ajax({
                url: "/User/DailySign/updateStep1",
                type: "post",
                dataType: 'json',
                data: {id: id,title: title,type: type,attach_image: attach_image,attach_word: attach_word,
                    attach_advice: attach_advice,image_sort: image_sort,word_sort: word_sort,advice_sort: advice_sort,
                    has_weather: has_weather,has_festival: has_festival},
                success:function(result){
                    if(result['code'] === 0){
                        alert('提交成功，请继续下一步');
                        $('input[name=id]').val(result['id']);
                        $('.step1').addClass('next-step').html('下一步');
                    }
                }
            });
        }
    }

    function step2(){
        if($('.step1').hasClass('next-step')){
            $('.sec-step1').hide();
            $('.sec-step2').show();
        }else{
            var id = $('input[name=id]').val();
            var title = $('input[name=title]').val();
            var type = $('input[name=type]:checked').val();
            var attach_image = $('select[name=attach_image] option:selected').val();
            var attach_word = $('select[name=attach_word] option:selected').val();
            var attach_advice = $('select[name=attach_advice] option:selected').val();
            var image_sort = $('input[name=image_sort]:checked').val();
            var word_sort = $('input[name=word_sort]:checked').val();
            var advice_sort = $('input[name=advice_sort]:checked').val();
            var has_weather = 0;
            var has_festival = 0;
            if($('input[name=has_weather]').prop('checked') === true){
                has_weather = 1;
            }
            if($('input[name=has_festival]').prop('checked') === true){
                has_festival = 1;
            }
            if(title === ''){
                alert('活动标题不能为空');
                return false;
            }
            if(attach_image === '-1'){
                alert('图库不能为空');
                return false;
            }
            if(attach_word === '-1'){
                alert('语录库不能为空');
                return false;
            }
            if(attach_advice === '-1'){
                alert('宜忌文库不能为空');
                return false;
            }
            $.ajax({
                url: "/User/DailySign/updateStep1",
                type: "post",
                dataType: 'json',
                data: {id: id,title: title,type: type,attach_image: attach_image,attach_word: attach_word,
                    attach_advice: attach_advice,image_sort: image_sort,word_sort: word_sort,advice_sort: advice_sort,
                    has_weather: has_weather,has_festival: has_festival},
                success:function(result){
                    if(result['code'] === 0){
                        alert('提交成功，请继续下一步');
                        $('.step1').addClass('next-step').html('下一步');
                    }
                }
            });
        }
    }

    $('#custom_image').change(function(){
        var files = this.files;
        var reader = new FileReader();
        reader.readAsDataURL(files[0]);
        reader.onload = function (e) {
            $.ajax({
                data: {image: e.target.result},
                dataType: 'json',
                url: '/User/DailySign/uploadImage',
                type: 'post',
                success: function (res) {
                    $('.custom-img').attr('src', res.msg);
                    $('input[name=custom_image]').val(res.msg);
                }
            });
        }
    })

</script>